package terra.model.map;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.zip.GZIPInputStream;

import terra.model.World;
import terra.model.map.Map.MapContainer;

public class MapLoader implements Runnable {

	Map map;

	public MapLoader(Map m) {
		map = m;
	}

	@Override
	public void run() {
		try {
			File mapFile = new File("map" + File.separator + map.index + ".map");
			FileInputStream fos = new FileInputStream(mapFile);
			GZIPInputStream gz = new GZIPInputStream(fos);
			ObjectInputStream oos = new ObjectInputStream(gz);
			map.container = (MapContainer) oos.readObject();
			oos.close();
			gz.close();
			fos.close();
			World.getInstance().groundListener.addListeners(map.index);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

}
